package com.fb.fbvedioplayer

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import com.bumptech.glide.Glide
import com.fb.fbvedioplayer.CustomView.FBVideoPlayerStandardShareButton
import kotlinx.android.synthetic.main.activity_rotation_videosize.*

/**
 * <pre>
 *     author : fb
 *     e-mail : 469517834@qq.com
 *     time   : 2018/04/16
 *     desc   : 视频方向和视频平铺类型展示
 * </pre>
 */
class ActivityRotationVideoSize : AppCompatActivity(), View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_rotation_videosize)
        initView()
        initData()
    }

    private fun initView() {
        rotation_to_90.setOnClickListener(this)
        video_image_display_fill_parent.setOnClickListener(this)
        video_image_display_fill_crop.setOnClickListener(this)
        video_image_diaplay_original.setOnClickListener(this)
        video_image_diaplay_defaut.setOnClickListener(this)
    }

    private fun initData() {
        //给播放器赋值
        var url = ApplicationDemo.getProxy(this).getProxyUrl(VideoConstant.videoUrlList[0])
        rotatioin_video_vp.setVideo(url, VideoConstant.videoTitles[0], FBVideoPlayerStandardShareButton.SCREEN_WINDOW_NORMAL)
        //设置封面图
        Glide.with(this).load(VideoConstant.videoThumbList[0]).into(rotatioin_video_vp.thumbImageView)

        //预先设置视频旋转一定角度
        rotatioin_video_vp.videoRotation = 90
    }

    override fun onClick(view: View?) {
        when (view!!.id) {
            R.id.rotation_to_90 -> FBVideoPlayerStandardShareButton.setTextureViewRotation(0)
            R.id.video_image_display_fill_parent -> FBVideoPlayerStandardShareButton.setVideoImageDisplayType(FBVideoPlayerStandardShareButton.VIDEO_IMAGE_DISPLAY_TYPE_FILL_PARENT)
            R.id.video_image_display_fill_crop -> FBVideoPlayerStandardShareButton.setVideoImageDisplayType(FBVideoPlayerStandardShareButton.VIDEO_IMAGE_DISPLAY_TYPE_FILL_SCROP)
            R.id.video_image_diaplay_original -> FBVideoPlayerStandardShareButton.setVideoImageDisplayType(FBVideoPlayerStandardShareButton.VIDEO_IMAGE_DISPLAY_TYPE_ORIGINAL)
            R.id.video_image_diaplay_defaut -> FBVideoPlayerStandardShareButton.setVideoImageDisplayType(FBVideoPlayerStandardShareButton.VIDEO_IMAGE_DISPLAY_TYPE_ADAPTER)
        }
    }


    override fun onPause() {
        super.onPause()
        FBVideoPlayerStandardShareButton.releaseAllVideos()
        //再次设置视频播放方式，以保证其他页面使用的是默认模式
        FBVideoPlayerStandardShareButton.setVideoImageDisplayType(FBVideoPlayerStandardShareButton.VIDEO_IMAGE_DISPLAY_TYPE_ADAPTER)
    }

    override fun onBackPressed() {
        if (FBVideoPlayerStandardShareButton.backPress()) {
            return
        }
        super.onBackPressed()
    }

}